<?php if(!defined('BASEPATH')) exit('No direct script allowed');

class mdl_apps extends CI_Model{
	
	function __construct()
	{
		parent::__construct();
	}
	
	function get_item($lim=0, $num=0,$arr_where='')
	{
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('tapps');
		if ($arr_where!=''){
			$this->db->where($arr_where);
		}
		$this->db->order_by("appsid", "asc");
		if ($lim!=0){
			$this->db->limit($lim,$num);
		}
		return $this->db->get();
	}
	
	function get_lastitem($lim=0, $num=0)
	{
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('tapps');
		
		$this->db->order_by("appsid", "desc");
		if ($lim!=0){
			$this->db->limit($lim,$num);
		}
		return $this->db->get();
	}
	function get_countitem($arr_where=''){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('tapps');
		if ($arr_where!=''){
			$this->db->where($arr_where);
		}
		return  $this->db->count_all_results();
	}
	
	function getItemById($id)
	{
		$this->db->flush_cache();
		$this->db->where('userid', $id);
		return $this->db->get('users');
		
	}

	function insert()
	{
		$this->db->flush_cache();
		$this->db->set('appsid', ''); 
		//$this->db->set('username', $username); 
		//$this->db->set('level_id', $data['level_id']); 

		
        $result = $this->db->insert('tapps');
		
		//$result=$this->db->insert('users', $data);
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	}
	
	function update($id, $data)
	{
		$this->db->flush_cache();
		$this->db->set('userid', $data['userid']); 
$this->db->set('username', $data['username']); 
$this->db->set('password', $data['password']); 
$this->db->set('level_id', $data['level_id']); 

		$this->db->where('userid', $id);
		//$result=$this->db->update('users', $data);
		$result=$this->db->update('users');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	}
	
	function delete($id)
	{
		
		$this->db->flush_cache();
		$this->db->where('userid', $id);
		$result = $this->db->delete('users');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
		
	}
	
}
